package com.woniuxy.company5.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.company5.dto.FinRepDto;
import com.woniuxy.company5.entity.FinRep;
import com.woniuxy.company5.service.FinRepService;
import com.woniuxy.company5.util.Result;
import com.woniuxy.company5.vo.FinRepVo;
import com.woniuxy.company5.vo.WorkOrderDrawingVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能描述
 *
 * @author PC
 * @date -2022/12/8-时间-17:44
 * @product company5
 */
@RestController
@RequestMapping("/FinReps")
public class FinRepController {
    @Resource
    private FinRepService finRepService;
    @PostMapping("selAll")
    public Result selAll(@RequestBody FinRepDto finRepDto){
        PageHelper.startPage(finRepDto.getCurrentPage(),finRepDto.getPageSize(),true);
        PageHelper.orderBy("id desc");
        List<FinRepVo> vos = finRepService.selAll(finRepDto);
        PageInfo<FinRepVo> pageInfo = new PageInfo<>(vos);
        return Result.ok().data("repList",vos).data("total",pageInfo.getTotal());
    }

    @PostMapping("")
    public Result add(@RequestBody FinRep finRep){
        int i = finRepService.insertSelective(finRep);
        if(i > 0){
            return Result.ok();
        }else{
            return Result.error();
        }

    }
    @GetMapping("{id}")
    public Result selOne(@PathVariable Long id){
        FinRep finRep = finRepService.selectByPrimaryKey(id);
        if(finRep != null){
            return Result.ok().data("list",finRep);
        }else {
            return Result.error();
        }
    }

    @GetMapping("")
    public Result WorkOrderDrawing(){
        List<WorkOrderDrawingVo> workOrderDrawingVo = finRepService.WorkOrderDrawingCome();
        return Result.ok().data("WorkOrderDrawingList",workOrderDrawingVo);
    }
    @PutMapping("")
    public Result update(@RequestBody FinRep finRep){
        int i = finRepService.updateByPrimaryKeySelective(finRep);
        if(i > 0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }
    @DeleteMapping("{id}")
    public Result del(@PathVariable Long id){
        int i = finRepService.deleteByPrimaryKey(id);
        if(i > 0){
            return Result.ok();
        }else{
            return Result.error();
        }
    }


}
